package com.hu.zhcc.shiro.controller.lww.member;



import com.hu.zhcc.shiro.entity.lww.member.*;
import com.hu.zhcc.shiro.service.lww.member.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author luowuwen
 * @since 2021-06-15
 */
@RestController("com.hu.zhcc.shiro.service.lww.member.TMemberService")
public class TMemberController {

    @Autowired
    private TMemberService memberService;


    @Autowired
    private TMemberInfoService tMemberInfoService;

    @Autowired
    private TMemberMedicalhistoryService memberMedicalhistoryService;

    @Autowired
    private TInterposeClassifyService service;

    @Autowired
    private TMemberDynamicinfoService dynamicinfoService;


    @GetMapping("/memberinfo")
    public List<TMember> getAllMember(){
        List<TMember> tMembers = memberService.queryAll();
        return tMembers;

    }

    @PostMapping("insertmember")
    public boolean addmember(@RequestBody TMember tMember){

        memberService.addmember(tMember);
        Integer memberid = Integer.valueOf(memberService.selectid());
        String selectid = String.valueOf(memberid);
        selectid="10000".substring(0,5-selectid.length())+selectid;
        tMember.setFileNumber(selectid);
        tMember.setId(memberid);
        memberService.addfileNumber(tMember);
        memberService.adduser(tMember);//添加用户会员

        service.insertInterpose(memberid);//人群分类表信息插入

        tMember.getTMemberDynamicinfo().setTMemberId(memberid);
        tMember.getTMemberInfo().setTMemberId(memberid);
        tMember.getTMemberMedicalhistory().setTMemberId(memberid);

        dynamicinfoService.insertTMemberDynamicinfo(tMember.getTMemberDynamicinfo());
        tMemberInfoService.insertMemberinfo(tMember.getTMemberInfo());
        boolean b = memberMedicalhistoryService.insetTMemberMedicalhistory(tMember.getTMemberMedicalhistory());

        return b;
    }

    @PostMapping("updatmember")
    public boolean updatemember(@RequestBody TMember tMember){

        tMember.getTMemberDynamicinfo().setTMemberId(tMember.getId());
        tMember.getTMemberInfo().setTMemberId(tMember.getId());
        tMember.getTMemberMedicalhistory().setTMemberId(tMember.getId());

        System.out.println(tMember.getTMemberDynamicinfo());
        dynamicinfoService.updateTMemberDynamicinfo(tMember.getTMemberDynamicinfo());
        tMemberInfoService.updateMemberinfo(tMember.getTMemberInfo());
        memberMedicalhistoryService.updateTMemberMedicalhistory(tMember.getTMemberMedicalhistory());

        boolean flag = memberService.updatemember(tMember);
        return flag;
    }

    @PostMapping("deletemember")
    public boolean deletemember(@RequestBody TMember tMember){
        return memberService.deletemeber(tMember);
    }


}

